package com.yiwei.zxp.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.fragment.BussinessMsgFragment;
import com.yiwei.zxp.view.HomeViewPager;
import com.yiwei.zxp.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class BussinessMsgActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.pager)
    HomeViewPager pager;

    private Unbinder unbiner;
    private final int TypeOne = 4;
    private final int TypeTwo = 3;
    private final int TypeThree = 2;
    private final int TypeFour = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bussiness_msg);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        int type = getIntent().getIntExtra("type", 0);
        int poi = 0;
        switch (type) {
            case TypeOne:
                poi = 0;
                break;
            case TypeTwo:
                poi = 1;
                break;
            case TypeThree:
                poi = 2;
                break;
            case TypeFour:
                poi = 3;
                break;
        }
        txtTitle.setText("消息");
        String[] titles = new String[]{"账户", "物流", "订单", "通知"};
        Fragment[] fragments = new Fragment[4];
        for (int i = 0; i < titles.length; i++) {
            BussinessMsgFragment fragment = new BussinessMsgFragment();
            Bundle bundle = new Bundle();
            switch (i) {
                case 0:
                    bundle.putInt("id", TypeOne);
                    break;
                case 1:
                    bundle.putInt("id", TypeTwo);
                    break;
                case 2:
                    bundle.putInt("id", TypeThree);
                    break;
                case 3:
                    bundle.putInt("id", TypeFour);
                    break;
            }
            fragment.setArguments(bundle);
            fragments[i] = fragment;
        }

        pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }

            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return fragments.length;
            }
        });
        tablayout.setupWithViewPager(pager);

        pager.setCurrentItem(poi);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
